/*
 * @Author: your name
 * @Date: 2021-05-19 17:06:31
 * @LastEditTime: 2021-05-31 00:30:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/summary/index.tsx
 */
import { IForm } from '@/components/form/formComponent';
import { Button, Card, Table, TablePaginationConfig } from 'antd';
import React, { useEffect } from 'react';
import { DownloadOutlined } from '@ant-design/icons';
import Title from '@/components/title';
import './index.less';
import { useRequest } from '@/.umi/plugin-request/request';
import { get_store_list, today_info } from '@/services/pages';
import useObj from '@/use/useObj';
import initPagination from '@/use/initPagination';
import _ from 'lodash';
import { IJudge, IS_TRUE } from '../../enum/index';
interface IProps {}

const Summary = (props: IProps) => {
  const [obj, setObj] = useObj({
    ...initPagination,
    visible: false,
    refresh: null,
    row: null,
  });
  const columns: IForm[] = [
    {
      key: 'project_name',
      dataIndex: 'project_name',
      title: '项目',
    },
    {
      key: 'origin_price',
      dataIndex: 'origin_price',
      title: '项目原价(元)',
      render: (text) => {
        return <span>{text / 100}</span>;
      },
    },
    {
      key: 'true_price',
      dataIndex: 'true_price',
      title: '实际销售价(元)',
      render: (text) => {
        return <span>{text / 100}</span>;
      },
    },
    {
      key: 'staff_name',
      dataIndex: 'staff_name',
      title: '技师',
    },
    {
      key: 'is_clock',
      dataIndex: 'is_clock',
      title: '是否点钟',
      render: (text) => {
        return IJudge[text as keyof typeof IJudge];
      },
    },
  ];
  const datalist = [
    {
      create_time: '2021-02-21',
    },
    {
      create_time: '2021-02-21',
    },
  ];

  const { data, error, loading } = useRequest(
    () =>
      today_info({
        page_size: obj.pagination.pageSize,
        page_num: obj.pagination.current,
      }),
    {
      refreshDeps: [obj.pagination, obj.refresh],
    },
  );

  useEffect(() => {
    setObj((obj) => {
      obj.pagination.total = data?.results[0]?.total || 0;
    });
  }, [data]);

  return (
    <Card
      className="summary"
      title="今日汇总"
      // extra={
      //   <Button type="primary" icon={<DownloadOutlined />}>
      //     导出
      //   </Button>
      // }
    >
      <Table
        loading={loading}
        columns={columns}
        dataSource={data?.results.todayProject}
        pagination={obj.pagination}
        onChange={(pagination: TablePaginationConfig): void => {
          const { current, pageSize } = pagination;
          setObj((obj: any) => {
            obj.pagination.current = current;
            obj.pagination.pageSize = pageSize;
            obj.onReFresh = Symbol();
          });
        }}
      />
      <Title>
        今日销售总计：￥{data?.results?.todayProjectPrice / 100 || 0}
      </Title>

      <div className="today">
        <div className="new-vip">
          <Title>
            今日新会员：
            {data?.results?.todayRecharge.length === 0 && <span>无</span>}
          </Title>
          <div className="content">
            {_.map(data?.results?.todayRecharge, (row, index) => {
              return (
                <div className="vip-li">
                  <span className="username">姓名：{row.user_name}</span>
                  充值：￥
                  {row.money / 100 || 0}
                </div>
              );
            })}
          </div>
        </div>
        <div className="total">
          <Title>今日总营收：</Title>
          <div className="money">￥{data?.results?.totalPrice / 100 || 0}</div>
        </div>
      </div>
    </Card>
  );
};
export default Summary;
